

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品详情页面</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<body>
<form class="layui-form" method="post">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">*编号</label>
                <div class="layui-input-block">
                    <input type="text" name="id" id="id" lay-verify="title" disabled="disabled"
                           value="${sessionScope.selectId.id}" autocomplete="off" placeholder="请输入编号(必填)"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*商品名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" value="${sessionScope.selectId.name}" lay-verify="title"
                           autocomplete="off"
                           placeholder="请输入商品名称(必填)"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*详细信息</label>
                <div class="layui-input-block">
                    <input type="text" name="subtitle" id="subtitle" value="${sessionScope.selectId.subtitle}"
                           lay-verify="title" autocomplete="off" placeholder="请输入标题(必填)"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*商品主图</label>
                <div class="layui-input-block">

                    <img src="${sessionScope.selectId.mainImage}" lay-verify="title" autocomplete="off" name="mainImage"
                         id="mainImage">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*价格</label>
                <div class="layui-input-block">
                    <input type="text" name="price" id="price" value="${sessionScope.selectId.price}" lay-verify="title"
                           autocomplete="off" placeholder="请输入价格(必填)"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品状态</label>
                <div class="layui-input-block">
                    <select name="status" id="status" lay-verify="title" aotocomplete="off">
                        <option value="1">上架</option>
                        <option value="2">下架</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品类别</label>
                <div class="layui-input-block">
                    <select name="categoryId" id="categoryId" lay-verify="title" aotocomplete="off">
                        <option value="1">手机</option>
                        <option value="2">电视</option>
                        <option value="3">平板</option>
                        <option value="4">出行</option>
                        <option value="5">音箱</option>
                        <option value="6">其他</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*颜色</label>
                <div class="layui-input-block">
                    <input type="text" id="color" name="color" value="${sessionScope.selectId.color}" lay-verify="title"
                           autocomplete="off" placeholder="请输入颜色(必填)"
                           class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*容量</label>
            <div class="layui-input-block">
                <input type="text" name="edition" id="edition" value="${sessionScope.selectId.edition}"
                       lay-verify="title" autocomplete="off" placeholder="请输入容量(选填)"
                       class="layui-input">
            </div>
        </div>

    </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" onclick="update()" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-ok"></i>
                修改产品
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                恢复
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    if (${sessionScope.selectId.status==1}) {
        $("#status").find("option[value='1']").prop("selected", true)
    } else {
        $("#status").find("option[value='2']").prop("selected", true)
    }
    if (${sessionScope.selectId.categoryId==1}) {
        $("#categoryId").find("option[value='1']").prop("selected", true)
    } else if (${sessionScope.selectId.categoryId==2}) {
        $("#categoryId").find("option[value='2']").prop("selected", true)
    } else if (${sessionScope.selectId.categoryId==3}) {
        $("#categoryId").find("option[value='3']").prop("selected", true)
    } else if (${sessionScope.selectId.categoryId==4}) {
        $("#categoryId").find("option[value='4']").prop("selected", true)
    } else if (${sessionScope.selectId.categoryId==5}) {
        $("#categoryId").find("option[value='5']").prop("selected", true)
    } else {
        $("#categoryId").find("option[value='6']").prop("selected", true)
    }

    function update() {
        if ($("#name").val() == "" || $("#subtitle").val() == "" || $("#price").val() == ""
            || $("#color").val() == "" || $("#edition").val() == "") {
            layer.msg('请填写完整的信息!', {
                icon: 2,
                time: 2000,//2秒关闭（如果不配置，默认是3秒）
                anim: 6,
                top: 5
            });
        } else {
            $.ajaxSettings.async = false
            $.post("${pageContext.request.contextPath}/RoleUpdate",
                {
                    id:${sessionScope.selectId.id},
                    name: $("#name").val(),
                    subtitle: $("#subtitle").val(),
                    price: $("#price").val(),
                    status: $("#status").val(),
                    categoryId: $("#categoryId").val(),
                    color: $("#color").val(),
                    edition: $("#edition").val()
                }, function (data) {
                    console.log(data)
                    if (data) {
                        layer.msg('修改成功!', {
                            icon: 1,
                            time: 2000,//2秒关闭（如果不配置，默认是3秒）
                            anim: 5,
                            top: 5
                        });

                        setTimeout(function(){//设置定时器
                            parent.location.reload(true);//刷新父级页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        },1000);
                    } else {
                        layer.msg('修改失败!', {
                            icon: 2,
                            time: 2000,//2秒关闭（如果不配置，默认是3秒）
                            anim: 6,
                            top: 5
                        });
                    }
                }, 'json')
        }
    }

</script>
</body>
</html>
